<template>
    <div class="edit-popup">
        <popup
            ref="popupRef"
            title="拒绝售后"
            :async="true"
            width="550px"
            @confirm="handleSubmit"
            @close="handleClose"
        >
            <el-form ref="formRef" :model="formData" label-width="80px">
                <div class="w-full">
                    <el-input
                        class="ls-input"
                        type="textarea"
                        v-model="formData.verify_remark"
                        placeholder="请输入拒绝理由"
                        :rows="5"
                    ></el-input>
                </div>
            </el-form>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import { aftersaleRefuse } from '@/api/order'

import Popup from '@/components/popup/index.vue'
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const route = useRoute()

const formData = reactive({
    id: route.query.id,
    verify_remark: ''
})

const open = () => {
    popupRef.value?.open()
}

const handleClose = () => {
    emit('close')
}
const setFormData = (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }
}
defineExpose({
    open,
    setFormData
})

//提交
const handleSubmit = async () => {
    await aftersaleRefuse(formData)
    popupRef.value?.close()
    emit('success')
}
</script>
